package com.kaifamiao.www.demo.do0809;

import java.util.Arrays;
import java.util.Comparator;

public class Demo02 {
    public static void main(String[] args) {

        Student stu = new Student();
        stu.setName("大雄");
        stu.setScore(65);

        Student stu1 = new Student();
        stu1.setName("胖虎");
        stu1.setScore(55);

        Student stu2 = new Student();
        stu2.setScore(85);
        stu2.setName("静香");
        Student[] stus = {stu, stu1, stu2};

//        Arrays.sort(stus, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getScore() - o2.getScore();
//            }
//        });
        sort(stus, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getScore()- o2.getScore();
            }
        });
        System.out.println(Arrays.toString(stus));

    }
    public static void sort(Student[] students, Comparator<Student>comparator){
        for (int i = 0;i < students.length-1;i++){
            for (int j = 0;j < students.length-i-1;j++){
                if (comparator.compare(students[j],students[j+1])>0){
                    Student p = students[j];
                    students[j] = students[j+1];
                    students[j+1] = p;
                }
            }
        }
    }
}
